package com.cbtx.module.common.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.cbtx.module.common.R;


public class CommentConfirmDialog extends Dialog {

  public Context mContext;
  public String mContent;
  public String mAgree;
  public OnDialogListener onDialogListener;

  public CommentConfirmDialog(@NonNull Context context) {
    super(context, R.style.MMTheme);
    this.mContext = context;
  }


  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);


    initView();
  }

  private void initView() {
    View contentView = LayoutInflater.from(mContext).inflate(R.layout.base_dialog_comfig, null);


    TextView tvContent = contentView.findViewById(R.id.tv_content);

    TextView tvAgree = contentView.findViewById(R.id.tv_agree);


    if (!TextUtils.isEmpty(mContent)) {
      tvContent.setText(mContent);

    }




    if (!TextUtils.isEmpty(mAgree)) {
      tvAgree.setText(mAgree);
      tvAgree.setVisibility(View.VISIBLE);

      tvAgree.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          if (onDialogListener != null) {
            onDialogListener.onAgree();
            dismiss();
          }
        }
      });
    }

//    setCancelable(false);
    setContentView(contentView);
  }



  public  CommentConfirmDialog setContent(String mContent) {
    this.mContent = mContent;
    return this;
  }



  public  CommentConfirmDialog setAgree(String mAgree) {
    this.mAgree = mAgree;
    return this;
  }

  public  CommentConfirmDialog setOnDialogListener(OnDialogListener onDialogListener) {
    this.onDialogListener = onDialogListener;
    return this;
  }


  public interface OnDialogListener {
    void onCancel();

    void onAgree();
  }
}
